package src.com.hpu.service;

import com.hpu.callback.LoginCallback;
import com.hpu.callback.ScanCallback;
import com.hpu.constants.HttpConstants;
import com.hpu.constants.UrlConstants;
import com.hpu.tools.InternetTools;
import com.hpu.tools.OkHttpTools;

import android.content.Context;
import android.os.Handler;

/**
 * 登录业务，发起登录请求，这里的vpnPw是加密过的密文
 * @author Administrator
 *
 */
public class LoginService{

	private Context context;
	private Handler handler;
	
	public LoginService(Context context,Handler handler) {
		this.context=context;
		this.handler=handler;
	}
	
	public void login(String number,String vpnPw,String jwPw) {
//		OkHttpTools.get(UrlConstants.getLoginUrl(number, vpnPw,jwPw),
//				new LoginCallback(handler));
		if(InternetTools.statusInternet(context)==InternetTools.NO_INTERNET)
			handler.sendEmptyMessage(HttpConstants.NO_INTERNET);
		else
		OkHttpTools.post(UrlConstants.getLoginUrl(number, vpnPw,jwPw),new LoginCallback(handler),
				new String[]{"stu_id","vpn_password","jw_password"},
				new String[]{number,vpnPw,jwPw});
	}

	public void loginWeb(String number,String vpnPw,String jwPw,String content){
		if(InternetTools.statusInternet(context)==InternetTools.NO_INTERNET)
			handler.sendEmptyMessage(HttpConstants.NO_INTERNET);
		else
		OkHttpTools.post(UrlConstants.INTERFACE_SCAN,new ScanCallback(handler),
				new String[]{"qr_id","stu_id","vpn_password","jw_password","key"},
				new String[]{content,number,vpnPw,jwPw,UrlConstants.INTERFACE_KEY});
	}
}
